<template>
	<view style="margin: 0 20upx;">
		<view style="padding: 0 20upx;background-color: #FFFFFF;border-radius: 5upx;border-bottom: 2upx solid #eeeeee;position: relative;box-shadow: 2upx 2upx 10upx #dddddd;display: flex;height: 120upx;line-height: 120upx;" @click="completed('暂不开票', -1)">
			<view style="flex: 6;height: 120upx;line-height: 120upx;padding: 0 20upx;font-size: 34upx;">
				<text style="padding-left: 15upx;">暂不开票</text><text style="font-weight: 555;padding-left:18upx;" v-if="moren" >默认</text>
			</view>
			<view style="flex: 1;height: 120upx;line-height: 120upx;">
				<image src="../../../static/vip.png" style="width: 30upx;height: 40upx;padding-top: 10upx;" mode=""></image>
			</view>
		</view>
		
		<view style="padding: 0 20upx;background-color: #FFFFFF;border-radius: 5upx;border-bottom: 2upx solid #eeeeee;position: relative;box-shadow: 2upx 2upx 10upx #dddddd;display: flex;height: 120upx;line-height: 120upx;" @click="completed('个人', 0)">
			<view style="flex: 6;height: 120upx;line-height: 120upx;padding: 0 20upx;font-size: 34upx;">
				<text style="padding-left: 15upx;">开个人发票</text><text style="font-weight: 555;padding-left:18upx;" v-if="!moren" >默认</text>
			</view>
			<view style="flex: 1;height: 120upx;line-height: 120upx;">
				<image src="../../../static/vip.png" style="width: 30upx;height: 40upx;padding-top: 10upx;" mode=""></image>
			</view>
		</view>
		
		<view v-for="(item,index) in res" :key="index" style="padding: 0 20upx;background-color: #FFFFFF;border-radius: 5upx;margin-top: 20upx;border-bottom: 2upx solid #eeeeee;position: relative;box-shadow: 2upx 2upx 10upx #eeeeee;" >
			<view style="padding: 20px 20upx 0;">
				<view @click="completed(item.company_name,item.id)">
					<view style="height: 60upx;line-height: 60upx;font-size: 38upx;font-weight: 555;">
						<view style="height: 60upx;line-height: 60upx;">{{item.company_name}}</view>
					</view>
					<view style="height: 80upx;line-height: 80upx;font-size: 32upx;display: flex;">
						<view style="text-align: left;flex: 1;height: 80upx;line-height: 80upx;">公司税号: {{item.tax_number}}</view>
					</view>
				</view>
				<view style="height: 90upx;line-height: 80upx;font-size: 32upx;border-top: 1upx solid #eeeeee;">
					<view style="height: 90upx;line-height: 80upx;color: #333333;display: inline-block;width: 200upx;" @click="edit(item.id)">
						编辑
						<image src="../../../static/edit.png" style="width: 40upx;height: 40upx;vertical-align: middle;margin-left: 10upx;"></image>
					</view>
					<view style="height: 80upx;line-height: 80upx;color: #333333;display: inline-block;" @click="del(item.id)">
						删除
						<image src="../../../static/delete.png" style="width: 40upx;height: 40upx;vertical-align: middle;margin-left: 10upx;"></image>
					</view>
				</view>
			</view>
		</view>
		
		<button type="default" style="background-color: #000;color: #fff;width: 550upx;position: fixed;bottom: 100upx;left: 50%;transform: translate(-50%, -50%);" @click="jump" data-src="./invoice_edit">+ 新增发票信息</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				moren: true, // 默认为不开票
				user_id:'',
				res: [],
				imagess:[],
				imgurl:'',
				index: 1, // index为0 时开关打开,跳转到订单页
				goodsmsg:{},
			};
		},
		onLoad:function(e){
			if(e.index == 0) {
				uni.getStorage({
					key: 'goodsmsg',
					success: (res) => {
						this.goodsmsg = res.data
					},
				});
				this.index = e.index
			}
			if (e.tax_id) {
				if(e.tax_id == -1) {
					this.moren = true
				} else {
					this.moren = false
				}
			}
			
			uni.showLoading()
			uni.getStorage({
				key: 'user_id',
				success: (res) => {
					this.user_id = res.data
					this.setAjax()
				},
				fail: () => {
					uni.navigateTo({
						url: '../../index/index'
					});
				}
			});
		},
		methods:{
			completed(name,id) {
				if(this.index == 0) {
					uni.setStorage({
						key: 'goods_tax_id',
						data: id
					})
					uni.setStorage({
						key: 'goods_tax_name',
						data: name
					})
					
					let o = this
					uni.navigateTo({
						url: '/pages/order/createOrder?orderid=' + o.goodsmsg.orderid + '&number=' + o.goodsmsg.number + '&sure=' + o.goodsmsg.sure + '&level_id=' + o.goodsmsg.level_id + '&group_id=' + o.goodsmsg.group_id + '&tax_name=' + name + '&tax_id=' + id
					})
				}
				
			},
			setAjax(){
				uni.request({
					url: 'https://cx.mingmeijt.com/Api/Tax/index',
					method: 'POST',
					header:{'Content-Type':'application/x-www-form-urlencoded'},
					data:{
						user_id: this.user_id,
						session_id: uni.getStorageSync("sessionid")
					},
					success: res => {
						if(res.data.code == 999){
							uni.navigateTo({
								url:'/pages/999/999'
							})
						};
						if(res.data.code == 998){
							uni.navigateTo({
								url:'/pages/login/login'
							})
						}
						console.log(res)
						this.res = res.data.data
					},
					fail: () => {},
					complete: () => {}
				});
				uni.hideLoading()
			},
			edit (id) {
				uni.navigateTo({
					url: './invoice_edit?id=' + id
				})
			},
			del(id) {
				uni.request({
					url: 'https://cx.mingmeijt.com/Api/Tax/deleteTax',
					method: 'POST',
					header:{'Content-Type':'application/x-www-form-urlencoded'},
					data:{
						user_id: this.user_id,
						id: id,
						session_id: uni.getStorageSync("sessionid")
					},
					success: res => {
						if(res.data.code == 999){
							uni.navigateTo({
								url:'/pages/999/999'
							})
						};
						uni.showToast({
							title: res.data.msg,
							icon: 'none'
						})
						if (res.data.code == 200) {
							setTimeout(()=> {
								this.setAjax()
							}, 1000);
						}
					},
					fail: () => {},
					complete: () => {}
				});
			},
			jump(e){
				uni.navigateTo({
					url: e.currentTarget.dataset.src
				});
			},
		}
	}
</script>

<style>
</style>
